package com.sgcc.activiti.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sgcc.common.core.web.page.PageDomain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import com.sgcc.common.log.annotation.Log;
import com.sgcc.common.log.enums.BusinessType;
import com.sgcc.common.security.annotation.PreAuthorize;
import com.sgcc.activiti.domain.OContentApp;
import com.sgcc.activiti.service.IOContentAppService;
import com.sgcc.common.core.web.controller.BaseController;
import com.sgcc.common.core.web.domain.AjaxResult;
import com.sgcc.common.core.utils.poi.ExcelUtil;
import com.sgcc.common.core.web.page.TableDataInfo;

/**
 * 资讯内容管理网上国网Controller
 * 
 * @author sgcc
 * @date 2021-03-31
 */
@RestController
@RequestMapping("/oContentApp")
public class OContentAppController extends BaseController
{
    @Autowired
    private IOContentAppService oContentAppService;

    /**
     * 查询资讯内容管理网上国网列表
     */
    //@PreAuthorize(hasPermi = "activiti:app:list")
    @GetMapping("/list")
    public TableDataInfo list(OContentApp oContentApp)
    {
        startPage();
        List<OContentApp> list = oContentAppService.selectOContentAppList(oContentApp);
        return getDataTable(list);
    }

    /**
     * 导出资讯内容管理网上国网列表
     */
    //@PreAuthorize(hasPermi = "activiti:app:export")
    @Log(title = "资讯内容管理网上国网", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OContentApp oContentApp) throws IOException
    {
        List<OContentApp> list = oContentAppService.selectOContentAppList(oContentApp);
        ExcelUtil<OContentApp> util = new ExcelUtil<OContentApp>(OContentApp.class);
        util.exportExcel(response, list, "app");
    }

    /**
     * 获取资讯内容管理网上国网详细信息
     */
    //@PreAuthorize(hasPermi = "activiti:app:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(oContentAppService.selectOContentAppById(id));
    }

    /**
     * 新增资讯内容管理网上国网
     */
    //@PreAuthorize(hasPermi = "activiti:app:add")
    @Log(title = "资讯内容管理网上国网", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OContentApp oContentApp)
    {
        oContentApp= oContentAppService.insertOContentApp(oContentApp);
        if(null==oContentApp){
            return AjaxResult.error("添加失败！");
        }else{
            return AjaxResult.success(oContentApp);
        }

    }

    /**
     * 修改资讯内容管理网上国网
     */
    //@PreAuthorize(hasPermi = "activiti:app:edit")
    @Log(title = "资讯内容管理网上国网", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OContentApp oContentApp)
    {
        int i=oContentAppService.updateOContentApp(oContentApp);
        if(0==i){
            return AjaxResult.error("修改失败！");
        }else{
            return AjaxResult.success(oContentApp);
        }
    }

    /**
     * 删除资讯内容管理网上国网
     */
    //@PreAuthorize(hasPermi = "activiti:app:remove")
    @Log(title = "资讯内容管理网上国网", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(oContentAppService.deleteOContentAppByIds(ids));
    }

    /**
     * 资讯内容管理网上国网列表数据
     */
    @ResponseBody
    //@RequiresPermissions("goshine:ocontentapp:oContentApp:list")
    @RequestMapping(value = "/data")
    //@ControllerLog(description = "资讯内容管理网上国网列表数据", module = "资讯内容管理", logType = LogType.ServiceType)
    public Map<String, Object> data(OContentApp oContentApp, HttpServletRequest request, HttpServletResponse response) throws Exception {
        return oContentAppService.findPageInfo(new PageDomain<OContentApp>(request, response), oContentApp);
    }

}
